"""将（键-值对组成的）序列转换为（键-列表组成的）字典"""

from collections import defaultdict

s = [("yellow", 1), ("blue", 2), ("yellow", 3), ("blue", 4), ("red", 1)]


def group_by():
    d = defaultdict(list)
    for k, v in s:
        d[k].append(v)

    return sorted(d.items())


print(group_by())
